package com.soldier.controller;

import com.soldier.domain.Users;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @Author soldier
 * @Date 20-5-1 上午9:02
 * @Email:583406411@qq.com
 * @Version 1.0
 * @Description:将session数据写入到mongodb数据中
 */
@RestController
@RequestMapping("/service1")
public class WebController {

    /**
     * 往HttpSession插入数据
     * http://localhost:8001/service1/setMsg?msg=hello
     * @param session
     * @param msg
     */
    @RequestMapping("/setMsg")
    public String setMsg(HttpSession session, String msg) {
        session.setAttribute("msg", msg);
        return "ok";
    }

    /**
     * 获取用户信息，保存到HttpSession中
     * SpringSession再讲信息保存到mongodb中
     * http://localhost:8001/service1/addUser?userName=admin&passWord=admin
     * @param session
     * @param users
     */
    @RequestMapping("/addUser")
    public String addUser(HttpSession session, Users users) {
        session.setAttribute("users", users);
        return "ok";
    }
}
